package com.feihong.txgw.tx_precenter;

import android.content.Intent;

import com.feihong.txgw.inter.contract.order.IPlaceOrderContract;
import com.feihong.txgw.model.bean.deliveryAdr.DeliveryAdrEntity;
import com.feihong.txgw.tx_model.PlaceOrderMainModel;

import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;

/**
 * @Author wangziheng
 * @ProjectName txgw_app
 * @ClassName PlaceOrderMainPrecenter
 * @package com.feihong.txgw.tx_precenter
 * @data 2018/5/7 15:48
 * @Describe
 * @Change
 */
public class PlaceOrderMainPrecenter extends IPlaceOrderContract. AbPlaceOrderMainPrecenter {
    @Override
    public void submitTerminalOrder(String adrID, String type, String renark, String goodsInfo) {
        mIModel.submitTerminalOrder(adrID, type, renark, goodsInfo).subscribe(new Observer<String>() {
            @Override
            public void onSubscribe(Disposable d) {
                mRxManager.register(d);
            }

            @Override
            public void onNext(String o) {
                mIView.submitTerminalOrderResult(o);
            }

            @Override
            public void onError(Throwable e) {
                mIView.loadDataError();
            }

            @Override
            public void onComplete() {
            }
        });
    }

    @Override
    public void parseBundle(Intent data) {
        mIModel.parseBundle(data).subscribe(new Consumer<DeliveryAdrEntity>() {
            @Override
            public void accept(DeliveryAdrEntity deliveryAdrEntity) throws Exception {
                mIView.parseBundle(deliveryAdrEntity);
            }
        });
    }

    @Override
    public IPlaceOrderContract.IPlaceOrderMainModel getModel() {
        return PlaceOrderMainModel.create();
    }

    public static PlaceOrderMainPrecenter create(){
        return new PlaceOrderMainPrecenter();
    }
    @Override
    public void onStart() {

    }
}
